﻿using System;
using personalplaner.business.common;
using personalplaner.business.stamm;
using personalplaner.common;
using personalplaner.dataprovider;
using System.Collections.Generic;

namespace personalplaner.servicemodel.dataaccess
{
    public interface IPensumDataAccess
    {
        Pensum GetPensum(int prsid);

        Pensum GetPensum(int prsid, DateTime stichdatum);

        IEnumerable<Pensum> GetPensen(int prsid);

		int GetPensumProzent(int prsid);

        int GetPensumProzent(int prsid, DateTime stichdatum);

        bool SetPensum(int prsid, int pensum, DateTime von, DateTime bis);

        bool SetKuendigung(int prsid, DateTime datum);

        #region Delete Methods

        bool DelPensum(Pensum pensum);

        #endregion
    }

    public class PensumDataAccess : BaseDataAccess, IPensumDataAccess
    {
        public PensumDataAccess(ISettingsProvider settings)
            : base(settings)
        {
        }

        #region Get Methods

        public Pensum GetPensum(int prsid)
        {
			using (new WaitCursor())
			{
				try
				{
					return DataServices.PensumService.GetPensum(Settings.DatabaseSettings, prsid);
				}
				catch (Exception)
				{
					//TODO: show a messagebox here with the error
				}

				return null;
			}
        }

        public Pensum GetPensum(int prsid, DateTime stichdatum)
        {
            using (new WaitCursor())
            {
                try
                {
					return DataServices.PensumService.GetPensum(Settings.DatabaseSettings, prsid, stichdatum);
                }
                catch (Exception)
                {
                    //TODO: show a messagebox here with the error
                }

                return null;
            }
        }

        public IEnumerable<Pensum> GetPensen(int prsid)
        {
            using (new WaitCursor())
            {
                try
                {
					return DataServices.PensumService.GetPensen(Settings.DatabaseSettings, prsid);
                }
                catch (Exception)
                {
                    //TODO: show a messagebox here with the error
                }

                return null;
            }
        }

		public int GetPensumProzent(int prsid)
		{
			using (new WaitCursor())
			{
				try
				{
					return DataServices.PensumService.GetPensumProzent(Settings.DatabaseSettings, prsid);
				}
				catch (Exception)
				{
					//TODO: show a messagebox here with the error
				}

				return 0;
			}
		}

        public int GetPensumProzent(int prsid, DateTime stichdatum)
        {
            using (new WaitCursor())
            {
                try
                {
					return DataServices.PensumService.GetPensumProzent(Settings.DatabaseSettings, prsid, stichdatum);
                }
                catch (Exception)
                {
                    //TODO: show a messagebox here with the error
                }

                return 0;
            }
        }

        #endregion

        #region Set Methods

        public bool SetPensum(int prsid, int pensum, DateTime von, DateTime bis)
        {
            using (new WaitCursor())
            {
                try
                {
					return DataServices.PensumService.SetPensum(Settings.DatabaseSettings, prsid, pensum, von, bis);
                }
                catch (Exception)
                {
                    //TODO: show a messagebox here with the error
                }
                return false;
            }
        }

        public bool SetKuendigung(int prsid, DateTime datum)
        {
            using (new WaitCursor())
            {
                try
                {
					return DataServices.PensumService.SetKuendigung(Settings.DatabaseSettings, prsid, datum);
                }
                catch (Exception)
                {
                    //TODO: show a messagebox here with the error
                }
                return false;
            }
        }

        #endregion

        #region Delete Methods

        public bool DelPensum(Pensum pensum)
        {
            using (new WaitCursor())
            {
                try
                {
                    return DataServices.PensumService.DelPensum(Settings.DatabaseSettings, pensum);
                }
                catch (Exception)
                {
                    //TODO: show a messagebox here with the error
                }
                return false;
            }
        }

        #endregion
    }
}
